﻿using System;
using System.Web;
using System.Configuration;

namespace eProject.WebHelper
{
    public static class ConnectionHelper
    {
        /// <summary>
        /// Function get connection string from web.config file
        /// </summary>
        /// <returns> sql connection string </returns>
        public static string GetConnectionString()
        {
            string pathToWebConfig = HttpContext.Current.Server.MapPath("~/Web.config");

            Configuration Configuration = ConfigurationManager.OpenMappedExeConfiguration(
                    new ExeConfigurationFileMap()
                    {
                        ExeConfigFilename = pathToWebConfig
                    },
                    ConfigurationUserLevel.None
            );

            return Configuration.ConnectionStrings.ConnectionStrings["MSSQLConnectionString"].ConnectionString;
        }
    }
}
